package com.fansl.allround.message.controller;

import com.corundumstudio.socketio.SocketIOClient;
import com.fansl.allround.message.api.constant.SocketConstant;
import com.fansl.allround.message.cache.ClientCache;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.UUID;

/**
 * @author fansl
 * @Description: TODO
 * @date 2019/9/4 17:13
 */
@RestController
@RequestMapping("/push")
public class PushController {
    @Resource
    private ClientCache clientCache;

    @GetMapping("/user/{userId}")
    public String pushTuUser(@PathVariable("userId") String userId, @RequestParam String message){
        HashMap<UUID, SocketIOClient> userClient = clientCache.getUserClient(userId);
        userClient.forEach((uuid, socketIOClient) -> {
            //向客户端推送消息
            socketIOClient.sendEvent(SocketConstant.SocketEvent.MessageEvent,"推送消息：“"+message+"”");
        });
        return "success";
    }
}
